package com.qfmy.web.app.mapper.common;

import com.qfmy.model.entity.common.BookSelf;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author 清风明月
 * @Package com.qfmy.web.app.mapper.novel
 * @date 2025/10/31
 * @description 小说书架mapper
 */
@Mapper
public interface BookSelfMapper {


    /**
     * 添加小说
     * @param novelSelf
     */
    void addNovelSelf(BookSelf novelSelf);

    /**
     * 判断小说是否在书架中
     * @param novelId
     * @param userId
     * @return
     */
    Boolean isInBookSelf(Integer novelId, Long userId);

    /**
     * 获取小说
     * @param userId
     * @param novelId
     * @return
     */
    BookSelf getBookSelf(Long userId, Integer novelId);

    /**
     * 修改小说
     * @param bookSelf
     */
    void updateBookSelf(BookSelf bookSelf);

    /**
     * 获取所有小说书架
     * @param userId
     * @return
     */
    List<BookSelf> getAllBookSelf(Long userId);

    /**
     * 删除小说
     * @param id
     */
    @Update("update book_self set is_delete = 1 where id = #{id}")
    void deleteBookSelf(Integer id);

    /**
     * 根据音频id获取小说
     * @param userId
     * @param audioId
     * @return
     */
    BookSelf getBookSelfByAudioId(Long userId, Integer audioId);

    /**
     * 添加音频
     * @param bs
     */
    void addBookSelf(BookSelf bs);

    /**
     * 获取小说数量
     * @param novelId
     * @return
     */
    @Select("select count(*) from book_self where novel_id = #{novelId} and is_delete = 0")
    Integer countNovels(Integer novelId);

    /**
     * 获取所有逻辑删除的
     * @return
     */
    List<BookSelf> getAllDeleted(Long userId);

    /**
     * 恢复小说
     * @param id
     * @param userId
     */
    @Update("update book_self set is_delete = 0 where id = #{id} and user_id = #{userId}")
    void findNovel(Integer id, Long userId);
}
